﻿Imports EIBWatcherNet.Core.EIB.Interfaces
Imports EIBWatcherNet.Core.EIB.Bus.Addressing

Namespace EIB.Managers
    Public NotInheritable Class EIBGroupAddressDataTypeManager
        Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger)

        Private _dataTypes As New Dictionary(Of UInt16, EIBDataTypeManger)


        Public Function Contains(address As EIBGroupAddress) As Boolean Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger).Contains
            Return _dataTypes.ContainsKey(address.ToUint16)
        End Function

        Public Function GetValue(address As EIBGroupAddress) As EIBDataTypeManger Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger).GetValue
            Return If(_dataTypes.ContainsKey(address.ToUint16), _dataTypes(address.ToUint16), Nothing)
        End Function

        Public Function GetEISValue(address As EIBGroupAddress) As EIBData.EIS.EIBDataEIS_Base
            Return If(_dataTypes.ContainsKey(address.ToUint16), _dataTypes(address.ToUint16).EISType, Nothing)
        End Function

        Public Function GetDPTValue(address As EIBGroupAddress) As EIBData.DPT.EIBDataDPT_Base
            Return If(_dataTypes.ContainsKey(address.ToUint16), _dataTypes(address.ToUint16).DPTType, Nothing)
        End Function

        Public Sub SetValue(address As EIBGroupAddress, value As EIBDataTypeManger) Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger).SetValue
            If _dataTypes.ContainsKey(address.ToUint16) Then
                _dataTypes(address.ToUint16) = value
            Else
                _dataTypes.Add(address.ToUint16, value)
            End If
        End Sub

        Public Sub SetValue(address As EIBGroupAddress, value As EIBData.EIS.EIBDataEIS_Base)
            If _dataTypes.ContainsKey(address.ToUint16) Then
                _dataTypes(address.ToUint16).EISType = value
            Else
                _dataTypes.Add(address.ToUint16, New EIBDataTypeManger(value))
            End If
        End Sub

        Public Sub SetValue(address As EIBGroupAddress, value As EIBData.DPT.EIBDataDPT_Base)
            If _dataTypes.ContainsKey(address.ToUint16) Then
                _dataTypes(address.ToUint16).DPTType = value
            Else
                _dataTypes.Add(address.ToUint16, New EIBDataTypeManger(value))
            End If
        End Sub

        Public Sub Clear() Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger).Clear
            _dataTypes.Clear()
        End Sub

        Public Sub Remove(address As EIBGroupAddress) Implements IEIBManager(Of EIBGroupAddress, EIBDataTypeManger).Remove
            If _dataTypes.ContainsKey(address.ToUint16) Then _dataTypes.Remove(address.ToUint16)
        End Sub
    End Class
End Namespace